﻿
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "ElementId.h"
#include "NdbObject.h"
#include "DbDataSchema.h"
#include "CutPlaneType.h"
#include "NdbObjectSchematic.h"
#include "VisibilityTypeEnums.h"
#include "IGraphicsNodeVisibilityFilter.h"

#include "GRepModule.h"

namespace gcmp
{
    class IModelView;
    class IGraphicsElementShape;
    enum class ModelViewDetailLevel;
}

namespace Sample
{
    // 仅对图形节点按照视图的详细程度做显示开关过滤
    class DetailLevelVisibilityFilter :public gcmp::NdbObjectSchematic, public gcmp::IGraphicsNodeVisibilityFilter
    {
        CANNOT_ASSIGN(DetailLevelVisibilityFilter);

        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(Sample, DetailLevelVisibilityFilter, gcmp::NdbObjectSchematic, A18DBF56 - 4DE5 - 4F67 - A09E - 5AF3F7EE9C8B, GRepModule, gcmp::IGraphicsNodeVisibilityFilter)
            DATA(gcmp::VisibilityType, DetailLevel)
        DBOBJECT_DATA_END

    public:
        virtual ~DetailLevelVisibilityFilter() {}

        // 根据当前视图判断图形节点是否显示
        virtual bool IsVisible(const gcmp::IModelView* pModelView) const override;

        virtual bool IsCuttable(const gcmp::IModelView* pModelView, gcmp::CutPlaneType cutPlaneType) const override;

        virtual gcmp::OwnerPtr<gcmp::IGraphicsNodeVisibilityFilter> Clone() const override;

        virtual void DeleteReferencedElementIds(const std::vector<gcmp::ElementId>& ids) override;

        DetailLevelVisibilityFilter(gcmp::VisibilityType detailLevel);

        virtual bool OnGraphicsNodeTransform(const gcmp::Matrix4d& matrix) override;

        virtual gcmp::NdbObject* GetTopOwnerObject() const override;

    private:
        gcmp::VisibilityType DetailLevelVisibilityFilter::ConvertModelViewDetailLevelToVisibilityType(gcmp::ModelViewDetailLevel detailLevel) const;
    };
}

